<template>
  <div class="mod-config">
    <el-form :inline="true" :model="searchForm" @keyup.enter.native="queryList()">

      <el-form-item>
<!--        <el-input v-model="searchForm.priorityLevel" placeholder="重要等级" clearable></el-input>-->
        <el-select v-model="searchForm.priorityLevel" filterable placeholder="请选择" style="width:100%">
          <el-option label="全部" value=""></el-option>
          <template v-for="(item, index) in dict.NoticeLevel">
            <el-option :label="item.value +': '+ item.label" :value="item.value"></el-option>
          </template>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="searchForm.noticeName" placeholder="通知名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="queryList(1)">查询</el-button>
<!--        <el-button type="" @click="addEntity()">新增</el-button>
        <el-button type="danger" @click="deleteEntity()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
      </el-form-item>
    </el-form>

    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="index" align="center"
        width="50"></el-table-column>
<!--           <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>-->

<!--           <el-table-column prop="id"  label="主键" header-align="center" align="center"></el-table-column>-->
           <el-table-column prop="priorityLevel"  label="等级" header-align="center" align="center" width="180">
             <template slot-scope="scope">
               <template v-for="(item, index) in dict.NoticeLevel">
                 <el-tag v-if="item.value == scope.row.priorityLevel" :type="item.style">
                   {{item.value}}: {{item.label}}
                 </el-tag>
               </template>
             </template>
           </el-table-column>
<!--           <el-table-column prop="noticeTitle"  label="通知标题" header-align="center" align="center"></el-table-column>-->
           <el-table-column prop="noticeName"  label="通知名称" header-align="center" align="left">
             <template slot-scope="scope">
               <span v-if="scope.row.priorityLevel == '0'" style="">{{ scope.row.noticeName}}</span>
               <span v-if="scope.row.priorityLevel == '1'" style="color: #dd6161 ">{{ scope.row.noticeName}}</span>
             </template>
           </el-table-column>
<!--           <el-table-column prop="noticeContext"  label="通知内容" header-align="center" align="center"></el-table-column>-->
<!--           <el-table-column prop="relType"  label="关联数据类型" header-align="center" align="center"></el-table-column>-->
<!--           <el-table-column prop="relId"  label="关联ID" header-align="center" align="center"></el-table-column>-->
           <el-table-column prop="createTime"  label="创建时间" header-align="center" align="center" width="180"></el-table-column>
<!--           <el-table-column prop="updateTime"  label="时间戳" header-align="center" align="center"></el-table-column>-->

<!--           <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
             <template slot-scope="scope">-->
<!--             	<el-button type="text" size="small" @click="modEntity(scope.row)">修改</el-button>-->
                <!--<el-button type="text" size="small" @click="showDetail(scope.row)">详细</el-button>-->
<!--                <el-button type="text" size="small" @click="deleteEntity(scope.row.id)">删除</el-button>-->
<!--             </template>
           </el-table-column>-->
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-entity v-if="addEntityVisible" ref="addEntity" @refreshDataList="queryList"></add-entity>
    <mod-entity v-if="modEntityVisible" ref="modEntity" @refreshDataList="queryList"></mod-entity>
    <show-detail v-if="showDetailVisible" ref="showDetail"></show-detail>
  </div>
</template>

<script>
  //import AddEntity from './notice-list-add'
  //import ModEntity from './notice-list-mod'
  //import ShowDetail from './notice-list-detail'
  import {mapState} from "vuex";

  export default {
    data() {
      return {
        isShow: false,
        searchForm: {
        },
        dataList: [],
        page: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addEntityVisible: false,
        modEntityVisible: false,
        showDetailVisible: false
      }
    },
    components: {
      //AddEntity, ModEntity, ShowDetail
    },
    activated() {
      this.queryList()
    },
    computed: mapState({
       // listType: state => state.goods.listType
    }),
    mounted() {
      // 数据字典查询
      //this.getSelectDict('FlowType').then((res) => {
      //  this.$store.commit('goods/updateListType', res)
      //})
    },
    methods: {
      // 获取数据列表
      queryList(clr) {
        if (typeof (clr) != 'undefined') {
          this.page = 1
        }
        this.dataListLoading = true
        let obj = {
          'page': this.page,
          'size': this.pageSize,
          //isTrans: true,
          //transParams: ['FlowType', 'ApplyResult', 'ReceiveStatus'],
          //transDict: ['flowType', 'applyResult', 'receiveStatus']
        }
        obj = Object.assign(obj, this.searchForm)
        this.getTableList('/api/notice/list', obj, (data) => {
          this.dataListLoading = false
          if (data.code == '000000' && data.rows && data.rows.length > 0) {
            this.dataList = data.rows
            this.totalPage = data.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.page = 1
        this.queryList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.page = val
        this.queryList()
      },
      // 多选
      selectionChangeHandle(val) {
        this.dataListSelections = val
      },
      // 新增
      addEntity() {
        this.addEntityVisible = true
        this.$nextTick(() => {
          this.$refs.addEntity.init()
        })
      },
      // 修改
      modEntity(row) {
        let cloneData = Object.assign({}, row)
        this.modEntityVisible = true
        this.$nextTick(() => {
          this.$refs.modEntity.init(cloneData)
        })
      },
      showDetail(row) {
        let cloneData = Object.assign({}, row)
        this.showDetailVisible = true
        this.$nextTick(() => {
          this.$refs.showDetail.init(cloneData)
        })
      },
      // 删除
      deleteEntity(id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行删除操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          	let obj = {"ids" : ids}
            this.getTableList('/api/notice-listDel', obj, (data) => {
            if (data && data.code ===  '000000' ) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.queryList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>